﻿@model Net.Web.Models.Jobs.JobCreateModel
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    //Html.AddScriptParts("~/Scripts/bootstrap-wysiwyg.js");
}

@using (Html.BeginForm("SaveJob", "Job", FormMethod.Post, new { @class = "form-horizontal" }))
{
    <fieldset>
        <div id="legend" class="">
            <legend class="">表单名</legend>
        </div>
        <div class="control-group">
            @Html.LabelFor(e => e.Name, new { @class = "control-label" })
            <div class="controls">
                @Html.TextBoxFor(e => e.Name, new { @class = "input-xlarge valtype" })
            </div>
        </div>
        <div class="control-group">
            @Html.LabelFor(e => e.Memo, new { @class = "control-label" })
            <div class="controls">
                @Html.EditorFor(e => e.Memo)
            </div>
        </div>
        <div class="control-group">
            @Html.LabelFor(e => e.WorkTypeId, new { @class = "control-label" })
            <div class="controls">
                @Html.DropDownListFor(e => e.WorkTypeId, Model.AvailableWorkType)
            </div>
        </div>

        <div class="control-group">
            @Html.LabelFor(e => e.CategoryId, new { @class = "control-label" })
            <div class="controls">
                @Html.DropDownListFor(e => e.CategoryId, Model.AvailableCategory,"请选择职位分类")
            </div>
        </div>
    </fieldset>
}

<script type="text/javascript">
    
    $(document).ready(function () {
        $("#@Html.FieldIdFor(model=>model.CategoryId)").change(function () {
            var selectedItem = $(this).val();            
            var current = $(this);
            if (selectedItem == -1)
                return;

            $.ajax({
                cache: false,
                type: "GET",
                url: "@(Url.RouteUrl("GetCategoryById"))",
                data: { "parentId": selectedItem},
                success: function (data) {
                    //这里数据返回成功后我想输出一个Select标签元素？
                    current.empty();
                    current.append("<option value=\"-1\">请选择职位分类</option>");
                    if (selectedItem > 0) {
                        current.append("<option value=\"0\">返回顶级</option>");
                    }
                $.each(data, function (id, option) {
                    current.append("<option value=" + option.Value + ">" + option.Text + "</option>");
                });
            },
            error: function (xhr, ajaxOptions, thrownError) {
                alert('Failed to retrieve states.');
                statesProgress.hide();
            }
        });
        });
    });
</script>